﻿namespace WriterStars.Infrastructure.Helpers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using WriterStars.Model;

    public abstract class Badge
    {
        public Badge()
        {
            this.Name = string.Empty;
            this.ImageUrl = string.Empty;
            this.HasBadge = false;
        }

        public string Name { get; set; }

        public string ImageUrl { get; set; }

        public bool HasBadge { get; set; }

        protected void Url(string name)
        {
            this.ImageUrl = string.Format("/content/badges/{0}", name);
        }
    }

    public class BookBadge : Badge
    {
        public BookBadge(Book book)
            :base()
        {
            this.Init(book);
        }

        private void Init(Book book)
        {
            this.ByLikes(book.Likes.Count);
        }

        private void ByLikes(int likeCount)
        {
            if (likeCount >= 5)
            {
                this.Name = "Fuzzy Duck";
                this.Url("bestchoice.png");
                this.HasBadge = true;
            }
            
            if(likeCount >= 10)
            {
                this.Name = "Almost Famous";
                this.Url("almostfamous.png");
                this.HasBadge = true;
            }
        }
    }
}